package com.selangshiwo.sina.biz;

import com.selangshiwo.Util;
import com.selangshiwo.sina.httpclient.SinaHttpClient;
import com.selangshiwo.sina.requst.PreLoginRequestPack;
import com.selangshiwo.sina.result.PreLoginResultPack;
import com.selangshiwo.sina.result.ResultPack;

public class PreLoginBiz implements IBaseHttpBiz {

	private String uName = "";
	
	private int retcode = -1 ;
	public String getuName() {
		return uName;
	}

	public int getRetcode() {
		return retcode;
	}

	public int getServertime() {
		return servertime;
	}

	public String getPcid() {
		return pcid;
	}

	public String getNonce() {
		return nonce;
	}

	private int servertime = -1 ;
	private String pcid = "";
	private String nonce = "";
	
	
	public PreLoginBiz(String uName){
		setUName(uName);
	}
	
	public void setUName(String uName){
		//不进行编码,在LoginBiz里统一处理
//		uName = uName.replace("@", "#");
//		this.uName = Util.base42Encode(uName.getBytes() );
		this.uName = uName ;
	}
	
	@Override
	public ResultPack run() {
		
		Util.debug("*前置登录业务准备+++++++++++++++++++");
		
		PreLoginRequestPack request = new PreLoginRequestPack();
		Util.debug("*设置用户： " + uName) ;
		request.setUserName(this.uName);
		Util.debug("*开始处理业务....");
		PreLoginResultPack result = (PreLoginResultPack) SinaHttpClient.getInstance().getRequest(request, PreLoginResultPack.class) ;
		Util.debug("业务处理结果 : " + result.getContext());
		if(result.getRetcode() != 0){
			Util.err("前置登录失败,请检查用户是否存在!");
		}else{
			this.retcode = result.getRetcode() ;
			this.pcid = result.getPcid() ;
			this.servertime = result.getServertime() ;
			this.nonce = result.getNonce() ;
		}
		return result;
	}

}
